package com.yanqu.road.server.manger.maidian.musicroom;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.musicroom.MusicRoomFurnitureInfo;
import com.yanqu.road.entity.musicroom.UserMusicRoomBeautyData;
import com.yanqu.road.entity.musicroom.UserMusicRoomBuildingData;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomModule;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.manger.config.MusicRoomConfigMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.maidian.BaseEventTraceAction;
import com.yanqu.road.server.manger.maidian.DefaultEventTraceAction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MusicRoomLog {
    public static void trackUserData(GamePlayer player) {
        //需求变动不用这个了
//        AttributeModule attributeModule = player.getModule(AttributeModule.class);
//        long badgeLv = attributeModule.getAttribute(ePlayerAttrType.MusicRoomBadgeLevel);
//        long prosperity = attributeModule.getAttribute(ePlayerAttrType.MusicRoomTotalProsperity);
//        Map<Integer, UserMusicRoomBuildingData> buildingDataMap = player.getModule(MusicRoomModule.class).getBuildingDataMap();
//        List<Integer> unlockBuildIds = new ArrayList<>();
//        for (Map.Entry<Integer, UserMusicRoomBuildingData> entry : buildingDataMap.entrySet()) {
//            int buildId = entry.getKey();
//            unlockBuildIds.add(buildId);
//        }

//        DefaultEventTraceAction action = new DefaultEventTraceAction("music_user", player);
//        action.build("music_userlv", badgeLv);
//        action.build("music_usernum", prosperity);
//        action.build("music_userlock", unlockBuildIds);
//        action.trace();
    }

    public static void trackLogoutMusicInfo(GamePlayer player) {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.MusicRoom.getValue())) {
            return;
        }
        AttributeModule attributeModule = player.getModule(AttributeModule.class);
        long badgeLv = attributeModule.getAttribute(ePlayerAttrType.MusicRoomBadgeLevel);
        long prosperity = attributeModule.getAttribute(ePlayerAttrType.MusicRoomTotalProsperity);
        Map<Integer, UserMusicRoomBuildingData> buildingDataMap = player.getModule(MusicRoomModule.class).getBuildingDataMap();
        Map<Integer, UserMusicRoomBeautyData> beautyDataMap = player.getModule(MusicRoomModule.class).getBeautyDataMap();
        long stageId = attributeModule.getAttribute(ePlayerAttrType.MusicRoomStageId);

        List<Integer> unlockBuildIds = new ArrayList<>();
        for (Map.Entry<Integer, UserMusicRoomBuildingData> entry : buildingDataMap.entrySet()) {
            int buildId = entry.getKey();
            unlockBuildIds.add(buildId);
        }

        Map<String, Object> lvUpMap = new HashMap<>();
        for (Map.Entry<Integer, UserMusicRoomBeautyData> entry : beautyDataMap.entrySet()) {
            int beautyId = entry.getKey();
            UserMusicRoomBeautyData beautyData = entry.getValue();
            int beautyLv = beautyData.getLevel();
            lvUpMap.put("intimate_name", beautyId);
            lvUpMap.put("music_beautylv", beautyLv);
        }

        DefaultEventTraceAction action = new DefaultEventTraceAction("music_info", player);
        action.build("music_userlv", badgeLv);
        action.build("music_usernum", prosperity);
        if (!unlockBuildIds.isEmpty()) {
            action.build("music_userlock", unlockBuildIds);
        }
        if (!lvUpMap.isEmpty()) {
            action.build("music_beautylvmap", lvUpMap);
        }
        action.build("music_playmaxid", stageId);
        action.trace();
    }

    public static void trackSpeedUpCardUsed(GamePlayer player, long count) {
        DefaultEventTraceAction action = new DefaultEventTraceAction("music_speedlog", player);
        action.build("music_speedcost", count);
        action.trace();
    }
}
